#ifndef SOCKET_HELPER_H
#define SOCKET_HELPER_H


#include <QWebSocket>
#include <QDebug>
#include "constant.h"
struct ChatData;
struct TableItem;
struct PersonNotifyhData;
struct TabaleData;
struct ChatTableData;
class SocketHelper
{
public:
    QWebSocket *websocket;
public :
    SocketHelper(QWebSocket *w);
    virtual ~SocketHelper();
protected:
    virtual void _send_socket_message(const int &code ,const QJsonObject &data) final;
    virtual  void on_connected()=0;
    virtual  void on_message(const QByteArray &message)=0;
    virtual  void on_message(const QString &message)=0;
    virtual  void on_disconnect()=0;
public:
};

class TableHelper : public virtual SocketHelper
{
public:
    TableHelper( QWebSocket *w);
    virtual void on_table_response_error(const int &code,const int &rep_code,const QString &rep_message,const QString &tag)=0;
    void on_connected() override;
    void on_message(const QByteArray &message)override;
    void on_message(const QString &message)override;
    void on_disconnect()override;
    void _send_chat_message(const QString &message);
    void _send_server_info_message(bool notify = true);
    virtual void on_chat_message(const ChatData &data)=0;
    virtual  void on_server_info_message(const QVector<TableItem> &data)=0;
    virtual void on_person_changed_notify(const PersonNotifyhData &data)=0;
};

class GameHelper :public virtual SocketHelper
{
protected :
    int table_id;
    int table_index;
public:
    virtual void on_game_response_error(const int &code,const int &rep_code,const QString &rep_message,const QString &tag)=0;

    void on_connected() override;
    void on_message(const QByteArray &message)override;
    void on_message(const QString &message)override;
    void on_disconnect()override;

    GameHelper(QWebSocket *w,int,int);

    void _send_join_table_message(int id,int index,int action);

    void _send_prepare_table_message(int id,int index,int action);

    void _send_chat_table_message(const QString &message);

    void _send_rob_table_message(int id,int index,int action);

    void _send_cards_table_message(int id,int index,const QVector<dymy::CARD_t> &cards);

    virtual void on_add_table_message(const TabaleData &data)=0;

    virtual void on_prepare_table_message(const TabaleData &data)=0;

    virtual void on_rob_table_message(const TabaleData &data)=0;

    virtual  void on_cards_table_message(const TabaleData &data) = 0;

    virtual void on_chat_table_message(const ChatTableData &data) = 0;
};




#endif // SOCKET_HELPER_H
